Skip to content

fix: repair failing tests and type errors across api and shared packages - #117

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2280-1785624452
Open

fix: repair failing tests and type errors across api and shared packages#117
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2280-1785624452

Conversation

@stooit

@stooit stooit commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all failing tests and TypeScript errors in the multi-package repo. Baseline was 9 failing tests and 14 type errors; now 22 pass / 0 fail and tsc --noEmit is clean (exit 0).

Changes

  • packages/shared/src/utils/pagination.ts — Implemented the paginate<T>() stub per the test contract: page slicing, total, totalPages (Math.ceil(total/pageSize), so 0 for empty), out-of-range pages return an empty slice, empty-array handling. Params clamped to a minimum of 1 and coerced against non-finite input.
  • packages/shared/src/types.ts — Renamed User.userNameusername to match the field name the tests assert.
  • packages/api/src/routes/users.ts — Added the missing badRequest import (from ../lib/errors), fixing the POST /users 400-on-missing-fields path.
  • packages/api/src/middleware/auth.ts — Fixed a case-sensitivity bug in the public-method allow-list. Now normalises the incoming method with toUpperCase() against a Set(["GET","POST"]), so GET/POST on /users are public regardless of casing and DELETE still 401s.
  • tsconfig.json — Added "types": ["bun-types"] (already present in node_modules, no new dependency) to resolve Cannot find module 'bun:test' and Cannot find name 'process'.

Verification

bun test   -> 22 pass, 0 fail
tsc --noEmit -> exit 0

Constraints honoured

  • No test files modified.
  • No new dependencies added (bun-types was already installed).

Notes / assumptions

  • Where a type and a test disagreed on a field name (userName vs username), the non-test source was changed to match the tests, per instructions.
  • Security flag (out of scope, not changed): the auth policy leaves POST /users unauthenticated, which the tests deliberately require. This permits anonymous user-record creation and email collection — worth a security review before this pattern reaches production, but it was left as the tests mandate.

- Implement paginate() stub in shared package with slicing, total,
  totalPages, and out-of-range/empty handling
- Rename User.userName -> username to match test contract
- Add missing badRequest import in users route
- Fix case-sensitivity bug in auth middleware public-method allow-list
- Wire up bun-types in tsconfig to resolve bun:test and process types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant